#include "UniquePhoneNumberValidator.h"
#include "NullPointerException.h"
UniquePhoneNumberValidator::UniquePhoneNumberValidator(const QString& field):PhoneNumberValidator(field)
{
	this->model = NULL;
}

UniquePhoneNumberValidator::~UniquePhoneNumberValidator(void)
{
}

int UniquePhoneNumberValidator::validate(QString& input)
{
	int v = PhoneNumberValidator::validate(input);
	if(v != 0)
		return v;
	if(this->model == NULL)
	{
		NullPointerException npe;
		npe.setMessage("Model has not been set");
		throw npe;
	}

	const Patient* p = model->getPatientManager()->findPatientByPhone(input + other);
	if(p != NULL)
	{
		this->message = "This " + this->field + " already exists"; 
		return -4;
	}
	return 0;
}